package com.jivam.lottery.model;

import java.io.Serializable;
/**
 * 统计期数中的数字
 * @author Jivam
 */
public class Num implements Comparable<Num>,Serializable{
	
	private static final long serialVersionUID = 1295443438114736150L;
	private String key;//统计的位置或公式 参考Constants.KEY_NUM
	private int[] position;//位置信息
	private int num;//数字列表 0-9
	private int period ;//多少期没出现
	
	public Num() {
	}

	public Num(int num, String key,int[] position) {
		this.num = num;
		this.key = key;
		this.position = position;
	}
	
	public void addPeriod(int num){
		if(this.num == num)
			period = 0;
		else
			period = period + 1;
	}

	public int getPeriod() {
		if(period > 999)//最大值
			return 999;
		return period;
	}

	public int getNum() {
		return num;
	}
	
	public String getKey() {
		return key;
	}
	
	public int[] getPosition() {
		return position;
	}

	public int compareTo(Num o) {
		return o.period - period;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		result = prime * result + num;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Num other = (Num) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		if (num != other.num)
			return false;
		return true;
	}
	
	

}
